import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';

import '../../../config/route/bt_app_router.gr.dart';
import '../../../data/models/bt_broadcaster.dart';
import '../models/bt_local_broadcaster.dart';

class BtBroadcasterItemWidget extends StatelessWidget {
  const BtBroadcasterItemWidget({
    super.key,
    required this.index,
    required this.item,
    required this.broadcasters,
  });

  final int index;

  final BtLocalBroadcaster item;

  final List<BtBroadcaster> broadcasters;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      child: Padding(
        padding: const EdgeInsets.only(left: 18, right: 13),
        child: Stack(children: [
          Container(
            padding: const EdgeInsets.only(top: 16, bottom: 16),
            decoration: const BoxDecoration(
              border: Border(
                bottom: BorderSide(
                  color: Color(0xFFEEEEEE),
                ),
              ),
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Container(
                  decoration: BoxDecoration(
                    gradient: const LinearGradient(
                      colors: [Color(0xFF14A7D5), Color(0xFF7F55F5)],
                    ),
                    borderRadius: BorderRadius.circular(34),
                    border: Border.all(width: 1, color: const Color(0xFF14A7D5)),
                  ),
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(34),
                    child: Image.asset(
                      item.localAvatar,
                      width: 68,
                      height: 68,
                      fit: BoxFit.cover,
                    ),
                  ),
                ),
                Expanded(
                    child: Padding(
                  padding: const EdgeInsets.only(left: 12),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(item.title,
                          maxLines: 1,
                          style: const TextStyle(
                              fontSize: 16, color: Color(0xFF14A7D5), fontWeight: FontWeight.bold)),
                      Text(item.about,
                          maxLines: 2,
                          style: const TextStyle(
                              fontSize: 10, color: Color(0xFF565656), fontWeight: FontWeight.normal)),
                    ],
                  ),
                )),
                Visibility(
                  visible: index == 0 || index == 1 || index == 2,
                  child: Image.asset(
                    _toNumImagePath(index),
                    width: 60,
                    height: 22,
                  ),
                )
              ],
            ),
          ),
          Visibility(
            visible: index == 0 || index == 1 || index == 2,
            child: Positioned(
              left: 38,
              top: 3,
              child: Image.asset(
                width: 34,
                height: 30,
                _toNumCrownImagePath(index),
                fit: BoxFit.cover,
              ),
            ),
          )
        ]),
      ),
      onTap: () {
        context.router.navigate(PostDetailsRoute(
          title: item.title,
          authorId: item.userId,
          authorName: item.nickname,
          avatar: item.avatar,
          broadcasters: broadcasters,
        ));
      },
    );
  }

  String _toNumImagePath(int index) {
    var imagePath = '';
    switch (index) {
      case 0:
        imagePath = 'assets/images/bt_num_one.png';
        break;
      case 1:
        imagePath = 'assets/images/bt_num_two.png';
        break;
      case 2:
        imagePath = 'assets/images/bt_num_three.png';
        break;
    }

    return imagePath;
  }

  String _toNumCrownImagePath(int index) {
    var imagePath = '';
    switch (index) {
      case 0:
        imagePath = 'assets/images/bt_crown_num_one.png';
        break;
      case 1:
        imagePath = 'assets/images/bt_crown_num_two.png';
        break;
      case 2:
        imagePath = 'assets/images/bt_crown_num_three.png';
        break;
    }

    return imagePath;
  }
}
